package norain.wxt.domain;

import norain.wxt.beans.Moudule;
import norain.wxt.data.BeanListHandler;
import norain.wxt.data.JdbcUtils;
import norain.wxt.data.ScalarHandler;
import norain.wxt.models.PagerList;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by wxt on 16/5/16.
 */
public class MouduleDao {

    public List<Moudule> GetMoudules() throws SQLException {
        String sql = "select * from city";
        Object params[] = {};
        return (List<Moudule>) JdbcUtils.query(sql, params, new BeanListHandler(Moudule.class));
    }

    public PagerList<Moudule> GetMoudulesPager() throws SQLException {
        PagerList<Moudule> pagerList = new PagerList<Moudule>();

        String countSql = "select count(Name) from Module";
        Object params[] = {};
        pagerList.Total = (Long) JdbcUtils.query(countSql, params, new ScalarHandler());

        String itemsSql = "select * from Module limit 5,5";

        pagerList.DataItems = (List<Moudule>) JdbcUtils.query(itemsSql, params, new BeanListHandler(Moudule.class));


        return pagerList;
    }

}
